import pygame
from pygame.sprite import LayeredUpdates

import config
from constants import resources

character = {
    "avatar": "",
    "current_time": 0.00,
    "name": "",
    "speed": 0.11
}


class character_avatar(LayeredUpdates):
    def __init__(self, character):
        super().__init__()
        self.character = character
        self.avatar_sprite = pygame.sprite.Sprite()
        self.avatar_sprite.image = pygame.transform.scale(resources.instance().image['1111'], [100, 100])
        self.avatar_sprite.rect = self.avatar_sprite.image.get_rect()
        self.add(self.avatar_sprite)
        self.v_x = self.character['speed']

    def update(self, ) -> None:
        if self.character['current_time'] >= config.maxTimeLine:
            ...
        else:
            self.character['current_time'] += self.v_x
            self.avatar_sprite.rect.centerx = self.character['current_time']
        print(self.character['current_time'])


class battle_line(LayeredUpdates):
    def __init__(self):
        super().__init__(self)
        self.surface = pygame.Surface([300, 10])
        self.min_num = -50.0
        self.start_num = 0.0
        self.max_num = 100.0

        global character
        character1 = character.copy()
        character1['name'] = "1"
        hero1 = character_avatar(character1)

        character2 = character.copy()
        character2['name'] = "2"
        character2['speed'] = 0.20
        hero2 = character_avatar(character2)
        hero2.avatar_sprite.rect.y = 200

        self.hero_list = [hero1, hero2]
        self.add(self.hero_list)
        self.enemy_list = []

    def update(self, ) -> None:
        for sp in self.hero_list:
            sp.update()
